package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.Dongtaihudong;
import com.ruoyi.system.mapper.DongtaihudongMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DongtaiMapper;
import com.ruoyi.system.domain.Dongtai;
import com.ruoyi.system.service.IDongtaiService;
import com.ruoyi.common.support.Convert;

/**
 * 动态管理 服务层实现
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Service
public class DongtaiServiceImpl implements IDongtaiService 
{
	@Autowired
	private DongtaiMapper dongtaiMapper;
	@Autowired
	private DongtaihudongMapper dongtaihudongMapper;

	/**
     * 查询动态管理信息
     * 
     * @param dongtaiId 动态管理ID
     * @return 动态管理信息
     */
    @Override
	public Dongtai selectDongtaiById(Integer dongtaiId)
	{
	    return dongtaiMapper.selectDongtaiById(dongtaiId);
	}
	
	/**
     * 查询动态管理列表
     * 
     * @param dongtai 动态管理信息
     * @return 动态管理集合
     */
	@Override
	public List<Dongtai> selectDongtaiList(Dongtai dongtai)
	{
	    return dongtaiMapper.selectDongtaiList(dongtai);
	}
	
    /**
     * 新增动态管理
     * 
     * @param dongtai 动态管理信息
     * @return 结果
     */
	@Override
	public int insertDongtai(Dongtai dongtai)
	{
	    return dongtaiMapper.insertDongtai(dongtai);
	}
	
	/**
     * 修改动态管理
     * 
     * @param dongtai 动态管理信息
     * @return 结果
     */
	@Override
	public int updateDongtai(Dongtai dongtai)
	{
	    return dongtaiMapper.updateDongtai(dongtai);
	}

	/**
     * 删除动态管理对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteDongtaiByIds(String ids)
	{
		return dongtaiMapper.deleteDongtaiByIds(Convert.toStrArray(ids));
	}

	/**
	 * 根据互动ID查找所有动态信息
	 * @param dongtaihudongId
	 * @return
	 */
	@Override
	public List<Dongtai> selectByHuDongId(Integer dongtaihudongId) {
		Dongtaihudong dongtaihudong = dongtaihudongMapper.selectDongtaihudongById(dongtaihudongId);
		List<Dongtai> dongtais = dongtaiMapper.selectDongtaiList(null);
		if(dongtaihudong != null){
				for(Dongtai dongtai:dongtais){
					if(dongtaihudong.getDongtaiId()==dongtai.getDongtaiId()){
						dongtai.setFlag(true);
					}
				}
			}

		return dongtais;
	}

}
